<h1>Editar art&iacute;culo "<?php echo $article->getTitle(); ?>"</h1>
<?php if($sf_user->hasFlash('msg')){ ?>
<div class="message">
  <?php echo $sf_user->getFlash('msg') ?>
</div>
<br />
<?php } ?>
<form action="<?php echo url_for('@articles_edit_save') ?>" method="post" id="frm" enctype="multipart/form-data" autocomplete="off">
    <input type="hidden" name="hdId" value="<?php echo $article->getId(); ?>" />
<table width="100%" cellpadding="5" cellspacing="5">
  <tr>
    <td>T&iacute;tulo</td>
    <td colspan="2"><input type="text" name="title" value="<?php echo $article->getTitle(); ?>" /></td>
  </tr>
  <tr>
    <td>Autor</td>
    <td colspan="2"><input type="text" name="author" value="<?php echo $article->getAuthor(); ?>" /></td>
  </tr>
  <tr>
    <td>N&uacute;mero</td>
    <td colspan="2"><input type="text" name="number" value="<?php echo $article->getNumber(); ?>" /></td>
  </tr>
  <tr>
    <td>PDF</td>
    <td>
        <?php $DS = DIRECTORY_SEPARATOR; ?>
        <?php if(file_exists(sfConfig::get('sf_upload_dir').$DS."article".$DS.$article->getId().'.pdf')){ ?>
          <a href="<?php echo public_path('uploads/article/'.$article->getId().'.pdf',true); ?>" target="_blank">Ver PDF</a>
        <?php } ?>
        <input type="file" name="pdf" />
    </td>
    <td><em style="color: gray;"></em></td>
  </tr>
  <tr>
    <td colspan="3">
        <h3>Publicaci&oacute;n a la que pertenece</h3>
        <em style="color: gray;">IMPORTANTE: Como m&aacute;ximo se muestran los primeros 20 resultados de la búsqueda ingresada</em>
        <table width="100%" cellpadding="5" cellspacing="5">
          <tr>
            <td width="100px">Buscar por titulo:</td>
            <td><input type="text" id="search_title" name="search_title" placeholder="Título de ejemplo"/></td>
            <td width="60px"><input type="button" value="Buscar" onclick="search()" /></td>
          </tr>
        </table>
      <div id="results">
        <table width="100%" cellpadding="5" cellspacing="0" border="1" class="list">
          <thead>
          <tr>
            <td width="25px">&nbsp;</td>
            <td>T&iacute;tulo</td>
            <td>Autor</td>
          </tr>
          </thead>
          <tbody>
          <tr>
            <td><input type="radio" name="publication_id" value="<?php echo $article->getPublications()->getId(); ?>" checked /></td>
            <td><?php echo html_entity_decode($article->getPublications()->getTitle()); ?></td>
            <td><?php echo $article->getPublications()->getAuthor(); ?></td>
          </tr>
          </tbody>
        </table>
      </div>
    </td>
  </tr>
  <tr>
    <td colspan="3" align="center">
      <input type="submit" value="Guardar Cambios" onclick="return v_frm()" style="padding: 10px;" />
    </td>
  </tr>
</table>
</form>
<script type="text/javascript">
$(document).ready(function(){
    $("#search_title").keypress(function(e){
        if(e.keyCode==13){
            search();
            return false;
        }
    });
});
function search(){
    var search_title = $("#search_title").val();

    $.ajax({
        type: "post",
        url: "<?php echo url_for('@ajax_search_publications_by_title') ?>",
        data: "title="+search_title,
        success: function(html){
            $("#results").html(html);
        }
    });
}
function v_frm(){
    if(!$("input[name='publication_id']").length){
        alert("Debes buscar y seleccionar una publicación");
        return false;
    }

    if(!$('input[name=publication_id]').is(':checked')){
         alert("Debes seleccionar una publicación");
        return false;
    }

    return true;
}
</script>